home *** CD-ROM | disk | FTP | other *** search
/ Ultra Pack / UltraComputing Partner Applications.iso / SunLabs / tclTK / src / tcl7.4 / tests / glob.test < prev    next >
Encoding:
Text File  |  1994-12-18  |  5.5 KB  |  149 lines

  1. # Commands covered:  glob
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1994 The Regents of the University of California.
  8. # Copyright (c) 1994 Sun Microsystems, Inc.
  9. #
  10. # See the file "license.terms" for information on usage and redistribution
  11. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12. #
  13. # @(#) glob.test 1.28 94/12/17 16:19:59
  14.  
  15. if {[string compare test [info procs test]] == 1} then {source defs}
  16.  
  17. # First, create some subdirectories to use for testing.
  18.  
  19. exec rm -rf globTest
  20. exec mkdir globTest globTest/a1 globTest/a2 globTest/a3
  21. exec mkdir globTest/a1/b1 globTest/a1/b2 globTest/a2/b3
  22. exec cat << abc > globTest/x1.c
  23. exec cat << abc > globTest/y1.c
  24. exec cat << abc > globTest/z1.c
  25. exec cat << abc > "globTest/weird name.c"
  26. exec cat << abc > globTest/.1
  27. exec cat << abc > globTest/a1/b1/x2.c
  28. exec cat << abc > globTest/a1/b2/y2.c
  29.  
  30. test glob-1.1 {simple globbing} {
  31.     lsort [glob globTest/x1.c globTest/y1.c globTest/foo]
  32. } {globTest/x1.c globTest/y1.c}
  33. test glob-1.2 {simple globbing} {
  34.     glob {}
  35. } .
  36.  
  37. test glob-2.1 {globbing with braces} {
  38.     glob -nocomplain "{a1,a2}"
  39. } {}
  40. test glob-2.2 {globbing with braces} {
  41.     lsort [glob globTest/{a,b,x,y}1.c]
  42. } {globTest/x1.c globTest/y1.c}
  43. test glob-2.3 {globbing with braces} {
  44.     lsort [glob {globTest/{x1,y2,weird name}.c}]
  45. } {{globTest/weird name.c} globTest/x1.c}
  46. test glob-2.4 {globbing with braces} {
  47.     lsort [glob globTest/{x1.c,a1/*}]
  48. } {globTest/a1/b1 globTest/a1/b2 globTest/x1.c}
  49.  
  50. test glob-3.1 {asterisks, question marks, and brackets} {
  51.     lsort [glob g*/*.c]
  52. } {{globTest/weird name.c} globTest/x1.c globTest/y1.c globTest/z1.c}
  53. test glob-3.2 {asterisks, question marks, and brackets} {
  54.     lsort [glob globTest/?1.c]
  55. } {globTest/x1.c globTest/y1.c globTest/z1.c}
  56. test glob-3.3 {asterisks, question marks, and brackets} {
  57.     lsort [glob */*/*/*.c]
  58. } {globTest/a1/b1/x2.c globTest/a1/b2/y2.c}
  59. test glob-3.4 {asterisks, question marks, and brackets} {
  60.     lsort [glob globTest/*]
  61. } {globTest/a1 globTest/a2 globTest/a3 {globTest/weird name.c} globTest/x1.c globTest/y1.c globTest/z1.c}
  62. test glob-3.5 {asterisks, question marks, and brackets} {
  63.     lsort [glob globTest/.*]
  64. } {globTest/. globTest/.. globTest/.1}
  65. test glob-3.6 {asterisks, question marks, and brackets} {
  66.     lsort [glob globTest/*/*]
  67. } {globTest/a1/b1 globTest/a1/b2 globTest/a2/b3}
  68. test glob-3.7 {asterisks, question marks, and brackets} {
  69.     lsort [glob {globTest/[xyab]1.*}]
  70. } {globTest/x1.c globTest/y1.c}
  71. test glob-3.8 {asterisks, question marks, and brackets} {
  72.     lsort [glob globTest/*/]
  73. } {globTest/a1/ globTest/a2/ globTest/a3/}
  74.  
  75. # The tests below are not portable, since they depend on a
  76. # particular location for ouster's home directory.
  77.  
  78. if $doNonPortableTests {
  79.     test glob-4.1 {tildes} {glob ~/.csh*} "/home/ouster/.cshrc"
  80.     test glob-4.2 {tildes} {glob ~ouster/.csh*} "/home/ouster/.cshrc"
  81.  
  82. test glob-5.1 {error conditions} {
  83.     list [catch {glob} msg] $msg
  84. } {1 {wrong # args: should be "glob ?switches? name ?name ...?"}}
  85. test glob-5.2 {error conditions} {
  86.     list [catch {glob globTest/\{} msg] $msg
  87. } {1 {unmatched open-brace in file name}}
  88. test glob-5.3 {error conditions} {
  89.     list [catch {glob globTest/*/gorp} msg] $msg
  90. } {1 {no files matched glob pattern "globTest/*/gorp"}}
  91. test glob-5.4 {error conditions} {
  92.     list [catch {glob goo/* x*z foo?q} msg] $msg
  93. } {1 {no files matched glob patterns "goo/* x*z foo?q"}}
  94. test glob-5.5 {error conditions} {
  95.     list [catch {lsort [glob globTest/*.c goo/*]} msg] $msg
  96. } {0 {{globTest/weird name.c} globTest/x1.c globTest/y1.c globTest/z1.c}}
  97. test glob-5.6 {error conditions} {
  98.     list [catch {glob ~no-one} msg] $msg
  99. } {1 {user "no-one" doesn't exist}}
  100. test glob-5.7 {error conditions} {
  101.     set home $env(HOME)
  102.     unset env(HOME)
  103.     set x [list [catch {glob ~/*} msg] $msg]
  104.     set env(HOME) $home
  105.     set x
  106. } {1 {couldn't find HOME environment variable to expand "~/*"}}
  107. test glob-5.8 {error conditions} {
  108.     list [catch {glob globTest/{a1,a2}/\{} msg] $msg
  109. } {1 {unmatched open-brace in file name}}
  110. test glob-5.9 {error conditions} {
  111.     list [catch {glob globTest/*/\{} msg] $msg
  112. } {1 {unmatched open-brace in file name}}
  113.  
  114. # On some systems, like AFS, "000" protection doesn't prevent
  115. # access by owner, so the following test is not portable.
  116.  
  117. if $doNonPortableTests {
  118.     exec chmod 000 globTest
  119.     test glob-6.1 {setting errorCode variable} {
  120.     string tolower [list [catch {glob globTest/*} msg]  $msg $errorCode]
  121.     } {1 {couldn't read directory "globtest": permission denied} {posix eacces {permission denied}}}
  122.     exec chmod 755 globTest
  123. }
  124.  
  125. test glob-7.1 {-nocomplain switch} {
  126.     list [catch {glob -nocomplai} msg] $msg
  127. } {1 {bad switch "-nocomplai": must be -nocomplain or --}}
  128. test glob-7.2 {-nocomplain switch} {
  129.     list [catch {glob -nocomplain} msg] $msg
  130. } {1 {wrong # args: should be "glob ?switches? name ?name ...?"}}
  131. test glob-7.3 {-nocomplain switch} {
  132.     list [catch {glob -nocomplain goo/*} msg] $msg
  133. } {0 {}}
  134. test glob-7.4 {-nocomplain switch} {
  135.     list [catch {glob -nocomplain ~xyqrszzz} msg] $msg
  136. } {0 {}}
  137. test glob-7.5 {-nocomplain switch} {
  138.     list [catch {glob ~xyqrszzz} msg] $msg
  139. } {1 {user "xyqrszzz" doesn't exist}}
  140. test glob-7.6 {-- switch} {
  141.     list [catch {glob -- -nocomplain} msg] $msg
  142. } {1 {no files matched glob patterns "-nocomplain"}}
  143. test glob-7.7 {bogus switch} {
  144.     list [catch {glob -gorp} msg] $msg
  145. } {1 {bad switch "-gorp": must be -nocomplain or --}}
  146.  
  147. exec rm -rf globTest
  148.